import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;



public class HandshakeMessage {
	//Members
	private ObjectInputStream ObjIn;
	private ObjectOutputStream ObjOut;
	HandshakeMessageFormat hfrmt;
	class HandshakeMessageFormat{
		byte[] header = new String("CEN5501C2008SPRING").getBytes();
		byte[] zeroBits = new byte[]{0,0,0,0,0,0,0,0,0,0};
		byte[] peerID = new byte[4];
	}
	
	HandshakeMessage(ObjectInputStream objIn,ObjectOutputStream objOut){
		this.ObjIn = objIn;
		this.ObjOut = objOut;
		HandshakeMessageFormat hfrmt = new HandshakeMessageFormat();
		hfrmt.peerID = PeerData.getPeerID().toString().getBytes();		
	}
	public void sendMessage() {
		try {
			hfrmt.peerID = PeerData.getPeerID().toString().getBytes();
			ObjOut.writeObject(hfrmt);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	public boolean recvMessage() {
		try {
			HandshakeMessageFormat obj = (HandshakeMessageFormat)ObjIn.readObject();
			if(obj.header == hfrmt.header){
				hfrmt = obj;
				return true;
			}
			else{
				System.out.println("Incorrct handshake message!");
				
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

}
